<template lang="html">
    <div class="box">
        <div class="header">
            <el-form class="filterCondition demo-form-inline" :inline="true" label-width="80px">
                <el-input placeholder="输入车主姓名/电话/微信昵称" v-model="keyword" style="width: 420px;">
                  <el-button slot="append" style="width: 120px;" @click="search()">搜索</el-button>
                </el-input>
            </el-form>
        </div>
        <div class="body">
            <el-table :data="tableData.list" style="width: 100%">
                <el-table-column label="头像" align="center" width="80">
                    <template slot-scope="scope">
                      <img :src="scope.row.head_pic" class="preview-img" :preview="scope.row.head_pic" alt="">
                    </template>
                </el-table-column>
                <el-table-column label="微信昵称" prop="nick_name" align="center" width=""></el-table-column>
                <el-table-column label="车主姓名" prop="name" align="center" width=""></el-table-column>
                <el-table-column label="电话" prop="phone" align="center" width=""></el-table-column>
                <el-table-column label="购卡次数" align="center" width="">
                    <template slot-scope="scope">
                        <el-button type="primary" @click="viewDetail(1,scope.row)" plain size="mini">{{scope.row.num}}次</el-button>
                    </template>
                </el-table-column>
                <el-table-column label="奖励详情" align="center" width="">
                  <el-table-column label="分享奖励" align="center" width="">
                    <template slot-scope="scope">
                      <el-button type="primary" @click="viewDetail(2,scope.row)" plain size="mini">查看详情</el-button>
                    </template>
                  </el-table-column>
                  <el-table-column label="推荐奖励" align="center" width="">
                    <template slot-scope="scope">
                      <el-button type="primary" @click="viewDetail(3,scope.row)" plain size="mini">查看详情</el-button>
                    </template>
                  </el-table-column>
                </el-table-column>
                <el-table-column label="停驶退费记录" align="center" width="">
                  <template slot-scope="scope">
                    <el-button type="primary" @click="viewDetail(4,scope.row)" plain size="mini">查看详情</el-button>
                  </template>
                </el-table-column>
            </el-table>
        </div>
        <div class="page_box">
            <el-pagination class="page" layout="prev, pager, next"
              @current-change="switchPage" :current-page="currentPage" :page-count='tableData.rows' >
            </el-pagination>
        </div>
        <div class="">
            <el-dialog title="购卡详情" :visible.sync="dialogTableVisible">
                <el-table :data="gridData">
                    <el-table-column align="center" property="card_number" label="卡号"></el-table-column>
                    <el-table-column align="center" property="card_price" label="购卡金额" width="110"></el-table-column>
                    <el-table-column align="center" property="plate" label="车牌号" width="90"></el-table-column>
                    <el-table-column align="center" label="车型" width="90">
                        <template slot-scope="scope">
                            <el-popover trigger="hover" placement="top">
                                <p>车型：{{ scope.row.name }}</p>
                                <p>车系：{{ scope.row.type }}</p>
                                <el-button slot="reference" class="name-wrapper" type="primary" plain size="mini">{{scope.row.name}}</el-button>
                            </el-popover>
                        </template>
                    </el-table-column>
                    <el-table-column align="center" property="company" label="维修厂"></el-table-column>
                    <el-table-column align="center" property="remain_times" label="剩余次数" width="80"></el-table-column>
                    <el-table-column align="center" property="card_type" label="套餐次数" width="80"></el-table-column>
                    <el-table-column align="center" property="sale_time" label="购卡时间"></el-table-column>
                </el-table>
            </el-dialog>
            <el-dialog title="分享奖励" :visible.sync="dialogTableVisible1">
                <el-table :data="gridData">
                    <el-table-column align="center" property="buyer" label="购卡者" ></el-table-column>
                    <el-table-column align="center" label="车型">
                        <template slot-scope="scope">
                            <el-popover trigger="hover" placement="top">
                                <p>车型：{{ scope.row.name }}</p>
                                <p>车系：{{ scope.row.type }}</p>
                                <el-button slot="reference" class="name-wrapper" type="primary" plain size="mini">{{scope.row.name}}</el-button>
                            </el-popover>
                        </template>
                    </el-table-column>
                    <el-table-column align="center" property="plate" label="车牌号"></el-table-column>
                    <el-table-column align="center" property="create_time" label="购卡时间"></el-table-column>
                    <el-table-column align="center" property="reward" label="奖励金额"></el-table-column>
                </el-table>
            </el-dialog>
            <el-dialog title="推荐奖励" :visible.sync="dialogTableVisible2">
                <el-table :data="gridData">
                    <el-table-column align="center" property="name" label="被推荐者"></el-table-column>
                    <el-table-column align="center" property="type_b" label="类型">
                        <template slot-scope="scope">
                          <p v-if="scope.row.type_b == 1">推荐维修厂</p>
                          <p v-if="scope.row.type_b == 2">推荐运营商</p>
                        </template>
                    </el-table-column>
                    <el-table-column align="center" property="create_time" label="奖励时间"></el-table-column>
                    <el-table-column align="center" property="money" label="奖励金额"></el-table-column>
                </el-table>
            </el-dialog>
            <el-dialog title="停驶退费记录" :visible.sync="dialogTableVisible3">
                <el-table :data="gridData.list">
                    <el-table-column align="center" property="create_time" label="时间" ></el-table-column>
                    <el-table-column align="center" property="refund_price" label="奖励金额"></el-table-column>
                    <el-table-column align="center" property="km" label="行驶里程"></el-table-column>
                    <el-table-column align="center" property="type" label="设备状态">
                        <template slot-scope="scope">
                          <p v-if="scope.row.type == 1">有信号</p>
                          <p v-if="scope.row.type == 0">无信号</p>
                        </template>
                    </el-table-column>
                </el-table>
                <div class="page_box">
                    <el-pagination class="page" layout="prev, pager, next"
                      @current-change="switchPage2" :page-count='pageCount' >
                    </el-pagination>
                </div>
            </el-dialog>
        </div>

    </div>
</template>

<script>
export default {
  data(){
    return {
      keyword: '',
      tableData:[],
      gridData:[],
      dialogTableVisible:false,
      dialogTableVisible1:false,
      dialogTableVisible2:false,
      dialogTableVisible3:false,
      pageCount:1,
      currentPage:1,
    }
  },
  created(){
    this.search()
  },
  methods:{
    search(){
      this.bbyuser()
    },
    bbyuser(page=1){
      this.currentPage = page;
      this.$http4.bbyuser({
        key: this.keyword,
        page: page,
      }).then(res=>{
        this.tableData = res.data.code == 1?
        res.data.data:[]
        this.$previewRefresh()
      })
    },
    viewDetail(n,e,page=1){
      this.currentRow = e;
      var j = {id:this.currentRow.id,page:page};
      this.gridData= []
      switch (n) {
        case 1:
          this.dialogTableVisible = true;
          this.$http4.bbyuserCard(j).then(res=>{
            this.gridData=res.data.code == 1?
            res.data.data:[]
          })
          break;
        case 2:
          this.dialogTableVisible1 = true;
          this.$http4.bbyuserShare(j).then(res=>{
            this.gridData=res.data.code == 1?
            res.data.data:[]
          })
          break;
        case 3:
          this.dialogTableVisible2 = true;
          this.$http4.bbyuserRecommend(j).then(res=>{
            this.gridData=res.data.code == 1?
            res.data.data:[]
          })
          break;
        case 4:
          this.dialogTableVisible3 = true;
          this.$http4.bbyuserRefund(j).then(res=>{
            this.gridData=res.data.code == 1?
            res.data.data:[]
            this.pageCount = this.gridData.rows
          })
          break;
        default:
          this.$message.error('出错了， 请联系管理员')
          break;
      }
    },
    switchPage(p){
      this.bbyuser(p)
    },
    switchPage2(p){
      this.viewDetail(4,this.currentRow,p)
    }

  }
}
</script>

<style lang="css" scoped>
@import "../../../my-style/app.css";

/deep/ .el-input-group__append, .el-input-group__prepend{
  background-color: #3498E9;
  border: none;
  color: white;
}

.preview-img{
  display: inline-block;
  width: 50px;
  height: 50px;
  border-radius: 100%;
  overflow: hidden;
}
.header{
  margin-bottom: 10px
}
.page_box{
  text-align: center;
}
</style>
